package m3;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;


import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Prodecer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Channel c = f.newConnection().createChannel();

        //创建fanout类型交换机
        c.exchangeDeclare("logs", "fanout");//名字，类型
        //向交换机发送消息
        while (true) {
            System.out.println("输入消息：");
            String s = new Scanner(System.in).nextLine();
            //对于fanout交换机，第二参数无效
            c.basicPublish("logs", "", null, s.getBytes());//发布信息：名字，持久，属性，数据
        }

    }
}
